//
//  VAProtocolHook.m
//  WKProxy
//
//  Created by Bennie on 16/4/22.
//  Copyright © 2016年 Bennett. All rights reserved.
//

#import "VAProtocolHook.h"
#import <RSSwizzle.h>
#include <objc/objc-runtime.h>

@implementation NSURLSession(Hook)


/**
 
 _NSURLHTTPProtocol,
 _NSURLDataProtocol,
 _NSURLFTPProtocol,
 _NSURLFileProtocol,
 NSAboutURLProtocol
 */
+ (void)load {



    NSArray *array = @[
//                       @"NSURLProtocol",
//                       @"_NSURLHTTPProtocol" ,
//                       @"_NSURLDataProtocol" ,
//                       @"_NSURLFTPProtocol" ,
//                       @"_NSURLFileProtocol" ,
//                       @"NSAboutURLProtocol" ,
//                       @"NSURLSessionConfiguration"
                       ];
    
    
    [array enumerateObjectsUsingBlock:^(id  _Nonnull objj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        Class obj = NSClassFromString(objj);
        
        unsigned int count;
        
        //获取属性列表
        objc_property_t *propertyList = class_copyPropertyList(obj, &count);
        for (unsigned int i=0; i<count; i++) {
            const char *propertyName = property_getName(propertyList[i]);
            NSLog(@"%@--property---->%@", NSStringFromClass(obj),[NSString stringWithUTF8String:propertyName]);
        }
        
        Method *methodList = class_copyMethodList(obj, &count);
        for (unsigned int i; i<count; i++) {
            Method method = methodList[i];
            SEL selector = method_getName(method);
//            NSLog(@"%@--Method---->%@", NSStringFromClass(obj),NSStringFromSelector(selector));
//            
//                        RSSwizzleClassMethod(obj, method_getName(method), RSSWReturnType(void), RSSWArguments(), RSSWReplacement(){
//                            RSSWCallOriginal();
//                            NSLog(@"%@---> %@.",NSStringFromClass(obj) ,NSStringFromSelector(selector));
//                        });
            
//            static const void *key = &key;
//            RSSwizzleInstanceMethod(obj,
//                                    selector,
//                                    RSSWReturnType(void),
//                                    RSSWArguments(),
//                                    RSSWReplacement(
//                                                    {
//                                                        NSLog(@"Deallocating %@.",self);
//                                                        RSSWCallOriginal();
//                                                    }), RSSwizzleModeOncePerClassAndSuperclasses, key);
        }
    }];
    
}





@end
